// https://www.bilibili.com/video/BV1ps4y1Q7gy/?spm_id_from=333.337.search-card.all.click&vd_source=16b267e92edd288778342448b69d98f9
// 学习抽象工厂的实现
#include <iostream>

class Product{
    public:
     Product() = default;
    virtual ~Product()  = default;
    virtual void show() = 0;
};

//抽象产品族
class Keyboard : public Product{};

//具体产品1
class LogiKeyboard : public Keyboard{
    public:
     void show(){
        std::cout << "LogiKeyboard" << std::endl;
    }
};

//具体产品2
class RazerKeyboard : public Keyboard{
    public:
    void show(){
        std::cout << "RazerKeyboard" << std::endl;
    }
};

//抽象产品2
class Mouse : public Product{};

//具体产品1
class LogiMouse : public Mouse{
    public:
    void show(){
        std::cout << "LogiMouse" << std::endl;
    }
};

// 具体产品2
class RazerMouse : public Mouse{
    public:
    void show(){
        std::cout << "RazerMouse" << std::endl;
    }
};

// 抽象工厂
class AbstractFactory{
    public:
    virtual Keyboard* createKeyboard() = 0;
    virtual Mouse* createMouse() = 0;
    virtual ~AbstractFactory() = default;
};   

//具体工厂1
class LogiFactory : public AbstractFactory{
    public:
    Keyboard* createKeyboard(){
    return new LogiKeyboard();
    }
    Mouse * createMouse(){
    return new LogiMouse();
    }
};

//具体工厂2
class RazerFactory : public AbstractFactory{
    public:
    Keyboard* createKeyboard(){
    return new RazerKeyboard();
    }
    Mouse * createMouse(){
    return new RazerMouse();
    }
};

int main()
{
    AbstractFactory* factory = new LogiFactory();
    Keyboard* keyboard = factory->createKeyboard();
    keyboard->show();
    Mouse* mouse = factory->createMouse();
    mouse->show();
    delete keyboard;
    delete mouse;
    delete factory;

    AbstractFactory* factory2 = new RazerFactory();
    Keyboard* keyboard2 = factory2->createKeyboard();
    keyboard2->show(); 
    Mouse* mouse2 = factory2->createMouse();
    mouse2->show();
    delete keyboard2;
    delete mouse2;
    delete factory2;


    return 0;
}